package com.objcat.servicea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.objcat.servicea.entity.po.UserPo;
import com.objcat.servicea.entity.vo.UserVo;
import com.objcat.servicea.mapper.UserMapper;
import com.objcat.servicea.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author misheep
 * @since 2020-07-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserPo> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean checkUser(String userName, String userPassword) {
        return false;
    }

    /**
     * 获取user的VO
     * @param userName
     * @param userPassword
     * @return
     */
    @Override
    public UserVo getUser(String userName, String userPassword) {
        QueryWrapper<UserPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", userName);
        UserPo user = userMapper.selectOne(queryWrapper);
        if(user==null) {
            return null;
        } else {
            //之后改成加密
            if(!user.getUserPassword().equals(userPassword)){
                return null;
            }
        }
        return user.getUserDto().getUserVo();
    }
}
